<template>
    <div>
        <mt-header fixed title="顶部标题栏">
            <a href="/" slot="left" @click.prevent="goBack " v-if="isShow">
                <mt-button icon="back">返回</mt-button>
            </a>
        </mt-header>

        <router-view class="content"></router-view>

        <nav class="mui-bar mui-bar-tab">
            <router-link class="mui-tab-item" to="/home">
                <span class="mui-icon mui-icon-home"></span>
                <span class="mui-tab-label">首页</span>
            </router-link>
            <router-link class="mui-tab-item" to="/vip">
                <span class="mui-icon mui-icon-contact"></span>
                <span class="mui-tab-label">会员</span>
            </router-link>
            <router-link class="mui-tab-item" to="/cart">
                <!-- 注意：mui-icon 必须要有，否则，样式错乱 -->
                <span class="mui-icon mui-icon-extra mui-icon-extra-cart">
          <span class="mui-badge">9</span>
        </span>
                <span class="mui-tab-label">购物车</span>
            </router-link>
            <router-link class="mui-tab-item" to="/search">
                <span class="mui-icon mui-icon-search"></span>
                <span class="mui-tab-label">搜索</span>
            </router-link>
        </nav>
    </div>
</template>

<script>
    import './lib/mui/css/icons-extra.css'
    // 注意导出的这个对象就是：当前组件的配置对象
    // Vue.component('hello', {  })
    export default {
        data() {
            return {
                isShow: false
            }
        },
        methods: {
            goBack() {
                this.$router.go(-1)
            }
        },
        created() {
            if (this.$route.path !== '/home') {
                this.isShow = true
            }
        },
        watch: {
            '$route'(to, from) {
                this.isShow = to.path !== '/home';
            }
        }
    }
</script>

<style scoped>
    .content {
        margin: 40px 0 50px 0;
    }

</style>

